package com.ruoyi.web.controller.comprehensive;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.comprehensive.dto.GasPreventionDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comprehensive.domain.GasPrevention;
import com.ruoyi.comprehensive.service.IGasPreventionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 瓦斯管理Controller
 * 
 * @author hcc
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/comprehensive/gas")
public class GasPreventionController extends BaseController
{
    @Autowired
    private IGasPreventionService gasPreventionService;

    /**
     * 查询瓦斯管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:list')")
    @GetMapping("/list")
    public TableDataInfo list(GasPrevention gasPrevention)
    {
        startPage();
        List<GasPrevention> list = gasPreventionService.selectGasPreventionList(gasPrevention);
        return getDataTable(list);
    }

    /**
     * 导出瓦斯管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:export')")
    @Log(title = "瓦斯管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasPrevention gasPrevention)
    {
        List<GasPrevention> list = gasPreventionService.selectGasPreventionList(gasPrevention);
        ExcelUtil<GasPrevention> util = new ExcelUtil<GasPrevention>(GasPrevention.class);
        util.exportExcel(response, list, "瓦斯管理数据");
    }

    /**
     * 获取瓦斯管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gasPreventionService.selectGasPreventionById(id));
    }

    /**
     * 新增瓦斯管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:add')")
    @Log(title = "瓦斯管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasPrevention gasPrevention)
    {
        gasPrevention.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(gasPreventionService.insertGasPrevention(gasPrevention));
    }

    /**
     * 修改瓦斯管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:edit')")
    @Log(title = "瓦斯管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasPrevention gasPrevention)
    {
        return toAjax(gasPreventionService.updateGasPrevention(gasPrevention));
    }

    /**
     * 删除瓦斯管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:remove')")
    @Log(title = "瓦斯管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gasPreventionService.deleteGasPreventionByIds(ids));
    }

    /**
     * 获取瓦斯管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:query')")
    @GetMapping("getGasPreventionById/{id}")
    public AjaxResult getGasPreventionById(@PathVariable("id") String id) {
        GasPreventionDto gasPreventionDto = gasPreventionService.getGasPreventionById(id);
        return success(gasPreventionDto);
    }
    /**
     * 查询瓦斯管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:gas:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(GasPrevention gasPrevention)
    {
        startPage();
        List<GasPreventionDto> list = gasPreventionService.getGasPreventionList(gasPrevention);
        return getDataTable(list);
    }
}
